<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">
        <label>后台管理平台</label>
      </div>
      <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
        <el-form-item >
          <el-input name="username"  v-model="loginForm.username" placeholder="用户名">
            <template #prepend>
              <el-button icon="el-icon-user"></el-button>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item >
          <el-input
            name="password"
            type="password"
            @keyup.enter="loginIn"
            v-model="loginForm.password"
            placeholder="密码"
          >
           <template #prepend>
              <el-button icon="el-icon-lock"></el-button>
            </template>
          </el-input>
        </el-form-item>
      </el-form>
      <div class="login-btn">
        <el-button type="primary" @click="loginIn">登录</el-button>
      </div>
    </div>
    <div class="bottom">版权所有：tang大神倾情创作</div>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'
import { mapGetters, mapMutations } from 'vuex'

export default {
  data: function () {
    return {
      userToken: '',
      loginForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    ...mapMutations(['setusername', 'setAuthorization', 'setislogin']),
    ...mapGetters(['getusername', 'getAuthorization', 'getislogin']),
    loginIn () {
      const _this = this
      if (this.loginForm.username === '' || this.loginForm.password === '') {
        // eslint-disable-next-line no-undef
        ElMessage.warning({
          message: '请输入用户名密码',
          type: 'warning'
        })
      } else {
        _this.userToken = '123456789'
        _this.setusername(_this.username)
        _this.setAuthorization(_this.userToken)
        _this.setislogin(true)
        const token = _this.getAuthorization()
        // eslint-disable-next-line no-undef
        ElMessage.warning({
          message: token,
          type: 'warning'
        })
        _this.$router.push('/')
      }
    }
  }
}
</script>
<style  scoped>
.login-wrap {
  position: relative;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-image: url(~@/assets/images/login.jpg);
  background-size: 100%;
}
.ms-title {
  width: 100%;
  height: 60px;
  text-align: center;
  font-size: 30px;
  color:maroon;
  border-bottom: 1px solid #ddd;
}

.ms-title label{
  float: left;
  margin: 10px 0px 0px 80px;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
  padding: 30px 30px;
}
.login-btn {
  text-align: center;
  margin: 0px 40px 10px 40px;
}
.login-btn button {
  width: 100%;
  height: 36px;
  margin-bottom: 30px;
}
.login-tips {
  font-size: 12px;
  line-height: 30px;
  color: #fff;
}
.bottom {
  text-align: center;
  position: fixed;
  width: 100%;
  height: 30px;
  line-height: 30px;
  bottom: 0;
  color: #eee;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.3);
}
</style>
